// pages/index/brandDetails/brandDetails.js
import config from "../../../utils/config.js";
Page({

  /**
   * Page initial data
   */
  data: {
    currentBrand: {},
    proList: [],
  },
  // delete \n
  clearN: function(str) {
    var newStr = str.split("\n");
    return newStr.join("");
  },

  /**
   * Lifecycle function--Called when page load
   */
  onLoad: function (options) {
    // console.log(options);
    var that = this;
    // get brand details
    wx.request({
      url: config.detail,
      data: {id: options.bid},
      success: function(res) {
        // console.log(res.data.data.brand);
        res.data.data.brand.simple_desc = that.clearN(res.data.data.brand.simple_desc);
        that.setData({
          currentBrand: res.data.data.brand,
        })
      }
    });
    // get product list of this brand
    wx.request({
      url: config.list,
      data: { brandId: options.bid,page:1,size:50},
      success: function(res) {
        // console.log(res.data.data.data);
        that.setData({
          proList: res.data.data.data
        })
      }
    });
  },
  // show goods details
  showGoodsDetails(e) {
    // console.log(e.currentTarget.dataset.gid);
    wx.navigateTo({
      url: '../../logs/details/details?id=' + e.currentTarget.dataset.gid,
    });
  },

  /**
   * Lifecycle function--Called when page is initially rendered
   */
  onReady: function () {

  },

  /**
   * Lifecycle function--Called when page show
   */
  onShow: function () {

  },

  /**
   * Lifecycle function--Called when page hide
   */
  onHide: function () {

  },

  /**
   * Lifecycle function--Called when page unload
   */
  onUnload: function () {

  },

  /**
   * Page event handler function--Called when user drop down
   */
  onPullDownRefresh: function () {

  },

  /**
   * Called when page reach bottom
   */
  onReachBottom: function () {

  },

  /**
   * Called when user click on the top right corner to share
   */
  onShareAppMessage: function () {

  }
})